package org.first;

import java.util.List;

/**
 * @author tiger54910
 * @create 2024/12/5 20:26
 */
public class MaxSubListSum {
    public static Integer maxSubSum(final List<Integer> values) {
        if (null == values || values.isEmpty()) {
            throw new NullPointerException("数组为空");
        }
        Integer max = Integer.MIN_VALUE;
        Integer currentSum = 0;
        for (int i = 0; i < values.size(); ++i) {
            if (currentSum <= 0) {
                currentSum = values.get(i);
            } else {
                currentSum += values.get(i);
            }
            if (currentSum > max) {
                max = currentSum;
            }
        }
        return max;
    }
}
